package ${setFeginPackageName};

import com.allen.common.domain.BaseResult;
import com.allen.common.domain.PagingResultDto;
import com.allen.common.plugin.session.Sessions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description:${tableAnnotation}接口类
 * @author ${author}
 * @date ${date}
 */
@Api(description = "${tableAnnotation}接口")
@Slf4j
@RestController
@RequestMapping("/${FEIGNAPI_PREFIX}/${tableRequestPath}")
public class ${SERVICEFEIGNAPI_CLASSNAME} {
    <#--@ApiOperation(value = "查询列表返回swagger注释", response = ImagesInfo.class, responseContainer = "List")-->

    private final ${SERVICEFEIGN_CLASSNAME} ${servicefeign_classname};

    public ${SERVICEFEIGNAPI_CLASSNAME}(${SERVICEFEIGN_CLASSNAME} ${servicefeign_classname}) {
        this.${servicefeign_classname} = ${servicefeign_classname};
    }

    @PostMapping("/create")
    @ApiOperation(value = "添加${tableAnnotation}")
    public ResponseEntity<BaseResult<Integer>> create${tableName}(@RequestBody ${tableName} ${tableNameFirstLow}, Sessions.User user){
        <#--log.debug("添加${tableAnnotation}\t param:{}",${tableNameFirstLow});-->

        ${tableNameFirstLow}.setCreateUser((String) user.getUser().get("name"));
        return ${servicefeign_classname}.create${tableName}(${tableNameFirstLow});
    }

    @PutMapping("/update/{id}")
    @ApiOperation(value = "根据id更新${tableAnnotation}")
    public ResponseEntity<BaseResult<Integer>> update${tableName}(@PathVariable("id") Long id, @RequestBody ${tableName} ${tableNameFirstLow}){
        <#--log.debug("根据id更新${tableAnnotation}\t id:{} param:{}",id,${tableNameFirstLow});-->

        return ${servicefeign_classname}.update${tableName}(id, ${tableNameFirstLow});
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "根据ids删除${tableAnnotation}")
    public ResponseEntity<BaseResult<Integer>> delete${tableName}s(@PathVariable("ids") String ids){
        <#--log.debug("根据ids删除${tableAnnotation}\t param:{}", ids);-->

        return ${servicefeign_classname}.delete${tableName}s(ids);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询${tableAnnotation}")
    public ResponseEntity<BaseResult<${tableName}>> find${tableName}(@PathVariable("id") Long id){
        <#--log.debug("根据id查找${tableAnnotation}\t param:{}", id);-->

        return ${servicefeign_classname}.find${tableName}(id);
    }

    @PostMapping("/pages")
    @ApiOperation(value = "查询${tableAnnotation}分页列表")
    public ResponseEntity<BaseResult<PagingResultDto<${tableName}>>> pageQuery${tableName}s(@RequestBody ${tableName} ${tableNameFirstLow}){
        <#--log.debug("查询${tableAnnotation}分页列表\t param:{}",${tableNameFirstLow});-->

        return ${servicefeign_classname}.pageQuery${tableName}s(${tableNameFirstLow});
    }

}
